git = "https://github.com/carllerche/hamcrest-rust.git"
rev = "05acf768"
+[dependencies.url]
+git = "https://github.com/servo/rust-url"
+rev = "98a28e85"
+
[[bin]]
name = "cargo"
test = false
use cargo::core::MultiShell;
use cargo::core::source::{Source, SourceId};
use cargo::sources::git::{GitSource};
-use cargo::util::{Config, CliResult, CliError, Require, human};
+use cargo::util::{Config, CliResult, CliError, human};
use url::Url;
docopt!(Options, "
fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
let Options { flag_url: url, flag_reference: reference, .. } = options;
- let url: Url = try!(from_str(url.as_slice())
- .require(|| human(format!("The URL `{}` you passed was \
- not a valid URL", url)))
+ let url: Url = try!(Url::parse(url.as_slice()).map_err(|e| {
+ human(format!("The URL `{}` you passed was \
+ not a valid URL: {}", url, e))
+ })
.map_err(|e| CliError::from_boxed(e, 1)));
let source_id = SourceId::for_git(&url, reference.as_slice());
use semver;
-use url::Url;
use std::hash::Hash;
use std::fmt;
use std::fmt::{Show,Formatter};
}
}
-trait ToUrl {
- fn to_url(self) -> Result<Url, String>;
-}
-
-impl<'a> ToUrl for &'a str {
- fn to_url(self) -> Result<Url, String> {
- Url::parse(self)
- }
-}
-
-impl ToUrl for Url {
- fn to_url(self) -> Result<Url, String> {
- Ok(self)
- }
-}
-
-impl<'a> ToUrl for &'a Url {
- fn to_url(self) -> Result<Url, String> {
- Ok(self.clone())
- }
-}
-
#[deriving(Clone, PartialEq)]
pub struct PackageId {
name: String,
use core::source::{SourceId, RegistryKind, GitKind, Location, Remote};
use core::{Dependency, PackageId, Summary, Registry};
- use util::CargoResult;
+ use util::{CargoResult, ToUrl};
fn resolve<R: Registry>(pkg: &PackageId, deps: &[Dependency], registry: &mut R)
-> CargoResult<Vec<PackageId>> {
impl ToDep for &'static str {
fn to_dep(self) -> Dependency {
- let url = from_str("http://example.com").unwrap();
+ let url = "http://example.com".to_url().unwrap();
let source_id = SourceId::new(RegistryKind, Remote(url));
Dependency::parse(self, Some("1.0.0"), &source_id).unwrap()
}
}
fn dep(name: &str) -> Dependency {
- let url = from_str("http://example.com").unwrap();
+ let url = "http://example.com".to_url().unwrap();
let source_id = SourceId::new(RegistryKind, Remote(url));
Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
}
fn dep_loc(name: &str, location: &str) -> Dependency {
- let url = from_str(location).unwrap();
+ let url = location.to_url().unwrap();
let source_id = SourceId::new(GitKind("master".to_string()), Remote(url));
Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
}
#[cfg(test)]
mod tests {
use super::{SourceId, Remote, GitKind};
+ use util::ToUrl;
#[test]
fn github_sources_equal() {
- let loc = Remote(from_str("https://github.com/foo/bar").unwrap());
+ let loc = Remote("https://github.com/foo/bar".to_url().unwrap());
let s1 = SourceId::new(GitKind("master".to_string()), loc);
- let loc = Remote(from_str("git://github.com/foo/bar").unwrap());
+ let loc = Remote("git://github.com/foo/bar".to_url().unwrap());
let mut s2 = SourceId::new(GitKind("master".to_string()), loc);
assert_eq!(s1, s2);
str::from_utf8(last).unwrap().to_string()
}
Remote(ref url) => {
- let path = canonicalize_url(url.path.path.as_slice());
+ let path = url.path().unwrap().connect("/");
+ let path = canonicalize_url(path.as_slice());
path.as_slice().split('/').last().unwrap().to_string()
}
};
use url::Url;
use core::source::Remote;
use super::ident;
+ use util::ToUrl;
#[test]
pub fn test_url_to_path_ident_with_path() {
}
fn url(s: &str) -> Url {
- from_str(s).unwrap()
+ s.to_url().unwrap()
}
}
pub use self::pool::TaskPool;
pub use self::dependency_queue::{DependencyQueue, Fresh, Dirty, Freshness};
pub use self::graph::Graph;
+pub use self::to_url::ToUrl;
pub mod graph;
pub mod process_builder;
pub mod hex;
mod pool;
mod dependency_queue;
+mod to_url;
--- /dev/null
+use url;
+use url::{Url, UrlParser};
+
+pub trait ToUrl {
+ fn to_url(self) -> Result<Url, String>;
+}
+
+impl ToUrl for Url {
+ fn to_url(self) -> Result<Url, String> {
+ Ok(self)
+ }
+}
+
+impl<'a> ToUrl for &'a Url {
+ fn to_url(self) -> Result<Url, String> {
+ Ok(self.clone())
+ }
+}
+
+impl<'a> ToUrl for &'a str {
+ fn to_url(self) -> Result<Url, String> {
+ UrlParser::new().scheme_type_mapper(mapper).parse(self).map_err(|s| {
+ s.to_string()
+ })
+ }
+}
+
+fn mapper(s: &str) -> url::SchemeType {
+ match s {
+ "git" => url::RelativeScheme("9418"),
+ "ssh" => url::RelativeScheme("22"),
+ s => url::whatwg_scheme_type_mapper(s),
+ }
+}
execs()
.with_stdout("")
.with_stderr(format!("Cargo.toml is not a valid manifest\n\n\
- invalid url `{}`: `url: Invalid character in scheme.\n", url)));
+ invalid url `{}`: `Relative URL without a base\n", url)));
})
test!(two_revs_same_deps {